{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "987eb4d0",
   "metadata": {},
   "source": [
    "## 代码的注释"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5ed0b63",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Author:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5bb91eeb",
   "metadata": {},
   "source": [
    "## 用户输入\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "60fe6e8a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:123\n",
      "密码:123\n",
      "123\n",
      "123\n"
     ]
    }
   ],
   "source": [
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")\n",
    "\n",
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "737c11f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "user1 = input(\"123\")\n",
    "password1 = \"123456\"\n",
    "\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")\n",
    "print(username)\n",
    "print(password)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "8757f8be",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123123\n",
      "账号:123\n",
      "密码:123\n"
     ]
    }
   ],
   "source": [
    "user1 = input(\"123\")\n",
    "password1 = \"123456\"\n",
    "\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "d5b2f57d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "admin123\n",
      "账号:123\n",
      "密码:123\n",
      "账号或密码不正确\n",
      "账号:123456\n",
      "密码:123456\n",
      "账号或密码不正确\n",
      "账号:123\n",
      "密码:123456\n",
      "欢迎123登录！\n"
     ]
    }
   ],
   "source": [
    "# 登录系统 迭代1 ：增加判断功能\n",
    "# 假设我们数据库有用户信息：\n",
    "user1 = input(\"admin\")\n",
    "password1 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1): \n",
    "    username = input(\"账号:\")\n",
    "    password = input(\"密码:\")\n",
    "\n",
    "    if user1 == username and password1 == password:\n",
    "        print(\"欢迎\"+user1+\"登录！\")\n",
    "    else:\n",
    "        print(\"账号或密码不正确\")\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7faa438e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：asd\n",
      "年龄：23\n",
      "工作：it\n",
      "收入：3000\n",
      "地区：guangdong\n",
      "-----INFO OF asd------\n",
      "姓名：asd\n",
      "年龄：23\n",
      "工作：it\n",
      "收入：3000\n",
      "地区：guangdong\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法二：占位符 %s str, 依次有序输入\n",
    "name = input(\"姓名：\")\n",
    "age = int(input(\"年龄：\")) # 强制将 str 转换成 int\n",
    "job = input(\"工作：\")\n",
    "salary = input(\"收入：\")\n",
    "reg = input(\"地区：\")\n",
    "\n",
    "info = '''-----INFO OF %s------\n",
    "姓名：%s\n",
    "年龄：%d\n",
    "工作：%s\n",
    "收入：%s\n",
    "地区：%s'''%(name,name,age,job,salary,reg)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "6c4164e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：345\n",
      "年龄：345\n",
      "工作：345\n",
      "收入：345\n",
      "地区：345\n",
      "-----INFO OF 345------\n",
      "姓名：345\n",
      "年龄：345\n",
      "工作：345\n",
      "收入：345\n",
      "地区：345\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法三：format() 格式化输出函数，参数传递，不需要考虑位置\n",
    "name = input(\"姓名：\")\n",
    "age = int(input(\"年龄：\")) # 强制将 str 转换成 int\n",
    "job = input(\"工作：\")\n",
    "salary = input(\"收入：\")\n",
    "reg = input(\"地区：\")\n",
    "\n",
    "info = '''-----INFO OF {姓名}------\n",
    "姓名：{姓名}\n",
    "年龄：{年龄}\n",
    "工作：{工作}\n",
    "收入：{收入}\n",
    "地区：{地区}'''.format(年龄 = age,姓名 = name,工作 = job,收入 = salary, 地区 = reg)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79d00f39",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "46ebb12b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您的支付宝余额为900\n",
      "-----商品清单-----\n",
      "男士皮鞋￥200\n",
      "围巾￥20\n",
      "袜子￥10\n",
      "女士高跟鞋￥300\n",
      "iPhone14￥10000\n",
      "请输入您要购买的商品编号1\n",
      "['20']\n"
     ]
    }
   ],
   "source": [
    "account = input(\"您的支付宝余额为\")\n",
    "account = int(account)\n",
    "\n",
    "if account >= 0:\n",
    "    print(\"-----商品清单-----\")\n",
    "product_list = [[\"男士皮鞋\",200],[\"围巾\",20],[\"袜子\",10],[\"女士高跟鞋\",300],[\"iPhone14\"]]\n",
    "print(product)\n",
    "number = input(\"请输入您要购买的商品编号\")\n",
    "numbers = ['200','20','10','300','10000']\n",
    "number = int(number)\n",
    "a = [int(account)]\n",
    "b = [numbers[number]]\n",
    "print(b)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "cec57508",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[1;32mIn [2]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m account \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m您的支付宝余额为\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m      2\u001b[0m account \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m(account)\n\u001b[0;32m      4\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m account \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m:\n",
      "File \u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:1075\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m   1071\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_allow_stdin:\n\u001b[0;32m   1072\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m StdinNotImplementedError(\n\u001b[0;32m   1073\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1074\u001b[0m     )\n\u001b[1;32m-> 1075\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1076\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1077\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1078\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1079\u001b[0m \u001b[43m    \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m   1080\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:1120\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m   1117\u001b[0m             \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m   1118\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[0;32m   1119\u001b[0m     \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[1;32m-> 1120\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterrupted by user\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28mNone\u001b[39m\n\u001b[0;32m   1121\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[0;32m   1122\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Message:\u001b[39m\u001b[38;5;124m\"\u001b[39m, exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "account = input(\"您的支付宝余额为\")\n",
    "account = int(account)\n",
    "\n",
    "if account >= 0:\n",
    "    print(\"-----商品清单-----\")\n",
    "product_list = [[\"男士皮鞋\",200],[\"围巾\",20],[\"袜子\",10],[\"女士高跟鞋\",300],[\"iPhone14\"]]\n",
    "print(product)\n",
    "number = input(\"请输入您要购买的商品编号\")\n",
    "numbers = ['200','20','10','300','10000']\n",
    "number = int(number)\n",
    "a = [int(account)]\n",
    "b = [numbers[number]]\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca2160df",
   "metadata": {},
   "source": [
    "### 要求：\n",
    "运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    "让用户输入商品编号进行商品的购买。\n",
    "用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    "用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ff024c0a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您的支付宝余额为900\n",
      "-----商品清单-----\n",
      "{1: ('男士皮鞋', 200), 2: ('围巾', 20), 3: ('袜子', 10), 4: ('女士高跟鞋', 300), 5: ('iPhone14', 10000)}\n",
      "请输入您要购买的商品编号1\n",
      "请输入需要购买的男士皮鞋的数量：2\n",
      "-----您的购物清单为-----\n",
      "您购买了男士皮鞋\n",
      "支付宝还剩余300元\n",
      "-----商品清单-----\n",
      "{1: ('男士皮鞋', 200), 2: ('围巾', 20), 3: ('袜子', 10), 4: ('女士高跟鞋', 300), 5: ('iPhone14', 10000)}\n",
      "请输入您要购买的商品编号2\n",
      "请输入需要购买的围巾的数量：1\n",
      "-----您的购物清单为-----\n",
      "您购买了围巾\n",
      "支付宝还剩余280元\n",
      "-----商品清单-----\n",
      "{1: ('男士皮鞋', 200), 2: ('围巾', 20), 3: ('袜子', 10), 4: ('女士高跟鞋', 300), 5: ('iPhone14', 10000)}\n",
      "请输入您要购买的商品编号0\n",
      "离开商城了~~~~~~~~~~~~~~~~~~~\n"
     ]
    }
   ],
   "source": [
    "account = input(\"您的支付宝余额为\")\n",
    "account = int(account)\n",
    "while True:   \n",
    "   \n",
    "    if account >= 0:\n",
    "                    print(\"-----商品清单-----\")\n",
    "                    product_list = {\n",
    "                    1:('男士皮鞋',200),\n",
    "                    2:('围巾',20),\n",
    "                    3:('袜子',10),\n",
    "                    4:('女士高跟鞋',300),\n",
    "                    5:('iPhone14',10000),\n",
    "                    }\n",
    "    print(product_list)\n",
    "\n",
    "    number = input(\"请输入您要购买的商品编号\")\n",
    "    if number.isdigit():\n",
    "        number = int(number)\n",
    "    if number ==0:\n",
    "        print(\"离开商城了~~~~~~~~~~~~~~~~~~~\")\n",
    "        break\n",
    "    if number not in product_list: \n",
    "        print(f\"您输入的商品编号{number}不在商品列表中，是不是搞错了？(请重新输入)\")\n",
    "    else: \n",
    "            product = product_list[number]\n",
    "            num = input(\"请输入需要购买的%s的数量：\" % product[0])                            \n",
    "            account -= int(num) * product[1]\n",
    "            \n",
    "    if int(num) * product[1] > account:\n",
    "                        print(\"金额不足，请充值\")\n",
    "                        account += int(input(\"请输入需要充值的金额：\"))\n",
    "                        print(\"充值成功，余额为：%d\" % account)\n",
    "    i = (0,1,2,3,4,5)\n",
    "    if number in i:\n",
    "            shopping = (\"您购买了%s\" % (product[0]))\n",
    "            print(\"-----您的购物清单为-----\")  \n",
    "            print(shopping)\n",
    "            account -= (int(num)-1) * product[1]\n",
    "            print(\"支付宝还剩余%d元\" % account)\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dbb28f18",
   "metadata": {},
   "outputs": [],
   "source": [
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c49e28c0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3d6859d6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
